/**
 * Created by lvlq on 16/1/7.
 */
var oauthService = require("./oauthController");
var jsapiService = require("./jsapiController");
var tokenService = require("./accessTokenController");
module.exports = function (app) {
    app.get("/oauth/getUrl", oauthService.getUrl);
    //app.use("/oauth/getUrlForWeb", oauthService.getUrlForWeb);
    app.get("/oauth/getOauth", oauthService.getOauth);
    app.get("/oauth/getOauthUserInfo", oauthService.getOauthUserInfo);

    app.post("/jsapi/getJsConfig", jsapiService.getJsConfig);
    //app.use("/jsapi/getCardExt", jsapiService.getCardExt);
    //app.use("/jsapi/getTicket", jsapiService.getTicket);
    //app.use("/jsapi/getLatestTicket", jsapiService.getLatestTicket);
    app.get("/accesstoken", tokenService.getAccessToken);
    
    app.get("/oauth/get", function (req, res) {
        var callback = "http://scgbg.weixinzjit.com/index/setsession";
        var oauthUrl = "http://api.weixinzjit.com/api.php/wx/oauth?callback=" + encodeURIComponent(callback);
        oauthUrl += "&type=userinfo";
        res.send(oauthUrl);
        //http://api.weixinzjit.com/api.php/wx/oauth?callback=http%3A%2F%2Fscgbg.weixinzjit.com%2Findex%2Frule&type=userinfo
    });

    app.post("/userinfo", function (req, res) {
        var userinfo = JSON.parse(new Buffer(req.body.data, 'base64').toString());
        req.session.user = userinfo;
        res.redirect("/index/rule");
    });
};